/*
 * Class name: Fish
 * Description: Fish
 * Author: HuyNA
 * Date: 20/04/2014
 */

#include "Fish.h"
#include "Constant.h"

CFish::CFish()
{
	initWithSpriteFrameName("fish1.png");
	this->runAction(fishSwimming());
	gStatus = isIdle;
	gScore = 0;
}

CFish::~CFish()
{

}

CCRepeatForever* CFish::fishSwimming()
{
	int numFrame = 2;
	/* Create CCArray with capacity */
	CCArray* frames = CCArray::createWithCapacity(numFrame);
	/* Return the shared instance of the Sprite Frame Cache */
	CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
	/* Loaded sprite into frames */
	char fileName[100] = {0};
	for(int i=1; i <= numFrame; i++)
	{
		/* Get file name */
		sprintf(fileName, "fish%d.png", i);
		/* Return an Sprite Frame that was previous added */
		CCSpriteFrame* spriteFrame = frameCache->spriteFrameByName(fileName);
		/* Add to frames */
		frames->addObject(spriteFrame);
	}
	/* Create animation from frames*/
	CCAnimation* animation = CCAnimation::createWithSpriteFrames(frames, SWIM_DURATION);
	/* Create animate*/
	CCAnimate* animate = CCAnimate::create(animation);
	//
	CCRepeatForever* repeat = CCRepeatForever::create(animate);
	/*Return*/
	return repeat;
}
